﻿// -----------------------------------------------------------------------
// <copyright file="XmlAdapter.cs" company="Hewlett-Packard">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace Ex1.XMLHelper
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.IO;
    using System.Xml.Serialization;
    using FacebookWrapper.ObjectModel;

    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    public class XmlAdapter
    {
        private static XMLHelper m_Helper = new XMLHelper();

        public static void SaveFileToXml(object i_Object, string i_DirectoryPathOfXML, string i_Path)
        {
            m_Helper.VerifyFileDirectoryExists(i_DirectoryPathOfXML);
            string fullPath;

            fullPath = Path.Combine(i_DirectoryPathOfXML, i_Path);

            m_Helper.SaveToXml(i_Object, fullPath);
        }

        public static object DeserializeXml(Type i_ObjectType, string i_DirectoryPathOfXML, string i_Path)
        {
            string fullPath;
            object newObject = null;

            fullPath = Path.Combine(i_DirectoryPathOfXML, i_Path);
            newObject = m_Helper.Deserialize(i_ObjectType, fullPath);

            return newObject;
        }

        public static string GetFileDirectory(User i_LoggedInUser)
        {
            string directoryPathOfXML = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), i_LoggedInUser.Id);
            return directoryPathOfXML;
        }
    }
}
